package org.datamining.gui.windows;

import java.awt.BorderLayout;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import org.datamining.utilities.PropertyFileLoader;
import org.datamining.utilities.PropertyProvider;

import net.java.dev.designgridlayout.DesignGridLayout;
import net.java.dev.designgridlayout.LabelAlignment;


/**
 * @author Betul Coskuner (coskunerbetul@gmail.com)
 * @since 18th May 2014
 * 	
 * Pencere sinifinin karmasik olan arka planini gizlemeye yarayan AbstractWindow sinifi
 * 
 */
public abstract class AbstractWindow {

	protected JFrame _frame = null;

	public JFrame frame() {
		return _frame;
	}

	protected void refreshWindow(){
		_frame.pack();
		_frame.repaint();
	}

	public void calistir(boolean exitOnClose) {
		
		//TODO: uygulama pencere ismi property dosyasindan cagriliyor
		PropertyFileLoader arayuzSozlugu = PropertyProvider.getGuiLanguageData();
		String title = arayuzSozlugu.getLanguageDataValue("application.title");
		_frame = new JFrame(title);
		_frame.setTitle(title);
		_frame.setDefaultCloseOperation(exitOnClose ? JFrame.EXIT_ON_CLOSE
				: WindowConstants.DISPOSE_ON_CLOSE);
		
		JPanel top = new JPanel();
		
		DesignGridLayout layout = new DesignGridLayout(top);
		top.setName("TOP");
		init(layout);
		JPanel resultPanel = build(layout);
		
		JPanel containerTop = new JPanel(new BorderLayout());
		containerTop.add(top, BorderLayout.WEST);
		containerTop.add(resultPanel, BorderLayout.CENTER);
		
		_frame.add(containerTop);
		_frame.pack();
		_frame.setLocationRelativeTo(null);
		_frame.setVisible(true);
	}

	protected void init(DesignGridLayout layout) {
		layout.labelAlignment(LabelAlignment.RIGHT);
		layout.withoutConsistentWidthAcrossNonGridRows();
	}

	protected void addTopPanel(JComponent top) {
		_frame.add(top);
	}
	
	protected JLabel newLabel(String name)
	{
		return new JLabel(name);
	}
	
	//bu metot bu s�n�f� kal�t�m alan s�n�fta Override edilmek zorunda
	protected abstract JPanel build(DesignGridLayout layout);

}
